package com.example.translateappjava.Singleton;

import android.content.Context;
import android.content.SharedPreferences;

public class GlobalData {
    private static GlobalData instance;
    private String globalVariable = "高血压人群"; // 默认值
    private String baseUrl = "http://47.120.15.23:6001"; // 默认服务器地址

    // 私有构造方法，防止外部直接创建实例
    private GlobalData() {
    }

    // 提供单例实例
    public static synchronized GlobalData getInstance() {
        if (instance == null) {
            instance = new GlobalData();
        }
        return instance;
    }

    // 初始化 globalVariable（仅在 Application 类中调用一次）
    public void initialize(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("checkbox_prefs", Context.MODE_PRIVATE);
        globalVariable = sharedPreferences.getString("globalVariable", "高血压人群");
        baseUrl = sharedPreferences.getString("baseUrl", "http://47.120.15.23:6001");
    }

    public String getGlobalVariable() {
        return globalVariable;
    }

    public void setGlobalVariable(String globalVariable) {
        this.globalVariable = globalVariable;
    }

    public String getBaseUrl() {
        return baseUrl;
    }

    public void setBaseUrl(String baseUrl) {
        this.baseUrl = baseUrl;
    }
}